package cn.wp.common.core.plugin.fileserver;

import cn.hutool.core.io.IoUtil;
import cn.wp.common.core.exception.WpServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

/**
 * 文件服务
 * Created by chenyb on 2019/09/30
 */
@Component
public class FileService {

    @Autowired
    private StorageStrategy storageStrategy;

    public FileInfo upload(InputStream inputStream, StrategyParameter parameter, StorageProcessHandler storageProcessHandler) {
        FileInfo fileInfo = storageStrategy.fileStore(inputStream, parameter, storageProcessHandler);
        return fileInfo;
    }

    public FileInfo upload(String filePath, StrategyParameter parameter, StorageProcessHandler storageProcessHandler) {
        try {
            FileInputStream fileInputStream = new FileInputStream(filePath);
            FileInfo fileInfo = storageStrategy.fileStore(fileInputStream, parameter, storageProcessHandler);
        } catch (FileNotFoundException e) {
            throw new WpServiceException("上传文件" + filePath + "不存在",e);
        }
        return null;
    }

}
